home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.10 Oct 90 / NewToolBox.π / CExecWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-08  |  8.7 KB  |  334 lines  |  [TEXT/KAHL]

  1. /*
  2. ------ T H E   W I N D O W  P R O C E D U R E 
  3.  
  4.         May 1989 - HA OLIVER
  5.  
  6. */
  7.  
  8. #include "Demo.h"
  9.  
  10.  
  11. extern    Rect        dragRect,growRect;
  12. extern    TEHandle    CurrentText;
  13. extern    ListHandle    CurrentList;
  14. extern    WindowPtr    CurrentPort;
  15. extern    Handle        ListList,TextList,PictList;
  16. extern    Boolean        isDoc;
  17. extern    int            dh,dv;
  18. static    WindowPtr    theWindow;
  19. static    EventRecord    theEvent;
  20.  
  21.  
  22. /*
  23. ------------- Grow
  24. */
  25.  
  26. DoGrow()
  27. {
  28. }
  29.  
  30. /*
  31. ----------------------  mouseDown is in    "theWindow" ...
  32. */
  33.  
  34. TestInContent(global)
  35. Point    global;
  36. {
  37.     Point            newOr,local;
  38.     Rect            contRect;
  39.     char            result;
  40.     TEHandle        theText;
  41.     ListHandle        theList;
  42.     int                inControlPart;
  43.     ControlHandle    theControl;
  44.     PicHandle        thePic;
  45.     
  46.     local=global;
  47.     GetWindowClip(&contRect,&newOr,theWindow);
  48.     SetOrigin(0,0);
  49.     GlobalToLocal(&local);
  50.     ClipRect(&(*theWindow).portRect);
  51.     
  52.     if (PtInRect(local,&contRect))
  53.         {
  54.             OffsetRect(&contRect,newOr.h,newOr.v);
  55.             ClipRect(&contRect);
  56.             SetOrigin(newOr.h,newOr.v);
  57.             local=global;
  58.             GlobalToLocal(&local);
  59.             
  60.             theText=FindText(local,theWindow);
  61.                 if (theText!=NULL)
  62.                     { if (theText!=CurrentText)
  63.                         { if (CurrentText!=NULL) TEDeactivate(CurrentText);
  64.                           TEActivate(theText);
  65.                           CurrentText=theText;
  66.                          }
  67.                        if (CurrentList!=NULL) LActivate(false,CurrentList);
  68.                        CurrentList=NULL;
  69.                        TEClick(local,false,CurrentText);
  70.                      }
  71.                 else
  72.                     {
  73.                         theList=FindList(true,local,theWindow);
  74.                         if (theList!=NULL)
  75.                             { if (theList!=CurrentList)
  76.                                 { if (CurrentList!=NULL) LActivate(false,CurrentList);
  77.                                   LActivate(true,theList);
  78.                                   CurrentList=theList;
  79.                                  }
  80.                                if (CurrentText!=NULL) TEDeactivate(CurrentText);
  81.                                CurrentText=NULL;
  82.                                result    =LClick(local,theEvent.modifiers,CurrentList);
  83.                              }
  84.                         else
  85.                             {
  86.                                 inControlPart=FindControl(local,theWindow,&theControl);
  87.                                 if (theControl!=NULL)
  88.                                      {
  89.                                          if (CurrentList!=NULL) LActivate(false,CurrentList);
  90.                                         CurrentList=NULL;
  91.                                         if (CurrentText!=NULL) TEDeactivate(CurrentText);
  92.                                         CurrentText=NULL;
  93.                                         
  94.                                          switch(inControlPart)
  95.                                              {
  96.                                                  case     inButton    :if (TrackControl(theControl,local,NULL)!=0) 
  97.                                                                       ExecControl(theControl);break;
  98.                                                  case    inCheckBox    :if (TrackControl(theControl,local,NULL)!=0)
  99.                                                                          {
  100.                                                                               switch(GetCtlValue(theControl))
  101.                                                                                   {
  102.                                                                                       case 1:SetCtlValue(theControl,0);break;
  103.                                                                                       case 0:SetCtlValue(theControl,1);break;
  104.                                                                                   }
  105.                                                                                ExecControl(theControl);
  106.                                                                           };break;
  107.                                                  case    inUpButton    :
  108.                                                  case    inDownButton:
  109.                                                  case    inPageDown    :
  110.                                                  case    inPageUp    :
  111.                                                  case    inThumb        :             
  112.                                                  default                :break;
  113.                                              
  114.                                              }
  115.                                      }
  116.                                  else
  117.                                      {
  118.                                          if (CurrentList!=NULL) LActivate(false,CurrentList);
  119.                                         CurrentList=NULL;
  120.                                         if (CurrentText!=NULL) TEDeactivate(CurrentText);
  121.                                         CurrentText=NULL;
  122.                                         
  123.                                          thePic=FindPict(local,theWindow);
  124.                                         if(thePic!=NULL)
  125.                                             {
  126.                                                 SysBeep(5);
  127.                                             }
  128.                                      }
  129.                             }
  130.                     }
  131.             SetCurrents(CurrentText,CurrentList,theWindow);
  132.         
  133.         }
  134. }
  135.  
  136. /*
  137. ----------------------  mouseDown on the desktop ...
  138. */
  139.  
  140.  
  141. DoMouseDown()
  142.     switch(FindWindow(theEvent.where,&theWindow))
  143.         {
  144.             case     inContent :if (theWindow!=FrontWindow()) 
  145.                                SelectWindow(theWindow);
  146.                                else TestInContent(theEvent.where);
  147.                                break;
  148.                                
  149.             case    inGoAway  :if (TrackGoAway(theWindow,theEvent.where))
  150.                                  {             
  151.                                              DeInstalWindow(theWindow);
  152.                                             CurrentText=NULL;
  153.                                             CurrentList=NULL;
  154.                                             if (FrontWindow()==NULL) isDoc=FALSE;    
  155.                                  };
  156.                                break;
  157.                       
  158.             case    inGrow    :if (theWindow!=FrontWindow()) 
  159.                                SelectWindow(theWindow);
  160.                                else if (WindowWithGrow(theWindow)) DoGrow();
  161.                                break;
  162.             case    inDrag    :DragWindow(theWindow,theEvent.where,&dragRect);break;
  163.             case    inZoomIn  :
  164.             case    inZoomOut :break;
  165.         }
  166. }
  167.  
  168. /*
  169. ---------------------- A key Down...
  170.  */
  171.  
  172.  
  173. DoKeyDown()
  174. {
  175.         Rect    contRect;
  176.         Point    newOr;
  177.         register char    key;
  178.         
  179.         GetWindowClip(&contRect,&newOr,theWindow);
  180.         OffsetRect(&contRect,newOr.h,newOr.v);
  181.         ClipRect(&contRect);
  182.         SetOrigin(newOr.h,newOr.v);
  183.         key        =theEvent.message & charCodeMask;
  184.         if (CurrentText!=NULL)  TEKey(key,CurrentText);
  185.         if (CurrentList!=NULL)  
  186.             { 
  187.                         ObscureCursor();
  188.                         ListKey(key,CurrentList);
  189.             }
  190. }
  191.  
  192. /*
  193. ---------------------- Update the Window 
  194. */
  195.  
  196. DoUpdate()
  197. {
  198.             Rect    contRect;
  199.             Point    newOr;
  200.  
  201.             BeginUpdate(theWindow);
  202.             EraseRect(&(*theWindow).portRect);
  203.             SetOrigin(0,0);
  204.             ClipRect(&(*theWindow).portRect);
  205.             if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
  206.             GetWindowClip(&contRect,&newOr,theWindow);
  207.             OffsetRect(&contRect,newOr.h,newOr.v);
  208.             ClipRect(&contRect); 
  209.             SetOrigin(newOr.h,newOr.v);
  210.             DrawPicts(theWindow);  
  211.             DrawTexts(theWindow);
  212.             DrawLists(theWindow);
  213.             DrawControls(theWindow);
  214.             EndUpdate(theWindow);
  215. }
  216.  
  217. /*
  218. ---------------------- Activate the Window
  219. */ 
  220.  
  221. DoActivate()
  222. {
  223.             Rect    contRect;
  224.             Point    newOr;
  225.             
  226.            if (theEvent.modifiers & activeFlag) 
  227.              {
  228.                SetOrigin(0,0);
  229.                ClipRect(&(*theWindow).portRect);
  230.                HiliteAllControls(CtlActive,theWindow);
  231.                if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
  232.                GetWindowClip(&contRect,&newOr,theWindow);
  233.                OffsetRect(&contRect,newOr.h,newOr.v);
  234.                ClipRect(&contRect);
  235.                SetOrigin(newOr.h,newOr.v);
  236.                ActivateText(theWindow);
  237.                ActivateList(theWindow);   
  238.              }
  239.            else
  240.              {
  241.                SetOrigin(0,0);
  242.                ClipRect(&(*theWindow).portRect);
  243.                HiliteAllControls(CtlInactive,theWindow);
  244.                if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
  245.                GetWindowClip(&contRect,&newOr,theWindow);
  246.                OffsetRect(&contRect,newOr.h,newOr.v);
  247.                ClipRect(&contRect);
  248.                SetOrigin(newOr.h,newOr.v);
  249.                DeactivateText(theWindow);
  250.                DeactivateList(theWindow);
  251.              }
  252. }
  253.  
  254. /*
  255. ---------------------- 
  256. */
  257.  
  258. DoNullEvent()
  259. {
  260. }
  261.  
  262. /*
  263. ---------------------- Resume or Suspend needed...
  264.  */
  265.  
  266. DoMulti()
  267. {
  268.     Rect    contRect;
  269.     Point    newOr;
  270.             
  271.     if (theEvent.message & 1)
  272.         {    
  273.                SetOrigin(0,0);
  274.                ClipRect(&(*theWindow).portRect);
  275.                HiliteAllControls(CtlActive,theWindow);
  276.                if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
  277.                GetWindowClip(&contRect,&newOr,theWindow);
  278.                OffsetRect(&contRect,newOr.h,newOr.v);
  279.                ClipRect(&contRect);
  280.                SetOrigin(newOr.h,newOr.v);
  281.                ActivateText(theWindow);
  282.                ActivateList(theWindow); 
  283.         }
  284.     else
  285.         {
  286.                SetOrigin(0,0);
  287.                ClipRect(&(*theWindow).portRect);
  288.                HiliteAllControls(CtlInactive,theWindow);
  289.                if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
  290.                GetWindowClip(&contRect,&newOr,theWindow);
  291.                OffsetRect(&contRect,newOr.h,newOr.v);
  292.                ClipRect(&contRect);
  293.                SetOrigin(newOr.h,newOr.v);
  294.                DeactivateText(theWindow);
  295.                DeactivateList(theWindow);
  296.         }
  297. }
  298.  
  299. /*
  300. ---------------------- This Function is called when  
  301.                         an Event occurs for "theWindow"
  302. */                         
  303.  
  304. pascal void MyWindow(anEventAdd,inWindow)
  305. EventRecord        *anEventAdd;
  306. WindowPtr        inWindow;
  307. {
  308.     
  309.     theWindow = inWindow;
  310.     theEvent  = *anEventAdd;
  311.     GetPort(&CurrentPort);
  312.     SetPort(theWindow);
  313.     switch(theEvent.what)
  314.         {
  315.             case    nullEvent     :DoNullEvent();break;
  316.             case    mouseDown     :DoMouseDown();break;
  317.             case    mouseUp       :break;
  318.             case    keyDown       :DoKeyDown();break;
  319.             case    keyUp         :break;
  320.             case    autoKey       :DoKeyDown();break;
  321.             case    updateEvt     :DoUpdate();break;
  322.             case    activateEvt   :DoActivate();break;
  323.             case    diskEvt       :break;
  324.             case    multiFinderEvt:DoMulti();break;
  325.             
  326.             default:break; /* HighLevelEvent ?  */
  327.        }
  328.      SetPort(CurrentPort);
  329. }
  330.  
  331. /*
  332. ---------------------
  333. */